// pages/product/details.js
var utils = require('../../utils/util.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		coindex:0,
		imgindex:0,
		phonenum:"121545445",
		imgs: [],
		pro:{},
		comment:[{proimg:"/images/bottom6.jpg",userimg:"/images/headimg1.jpg",username:"罗纳尔多",content:"质量不错，很好，好评"},
			{ proimg: "/images/bottom6.jpg", userimg: "/images/headimg1.jpg", username: "罗纳尔多", content: "质量不错，很好，好评" },
			{ proimg: "/images/bottom6.jpg", userimg: "/images/headimg1.jpg", username: "罗纳尔多", content: "质量不错，很好，好评" },
			{ proimg: "/images/bottom6.jpg", userimg: "/images/headimg1.jpg", username: "罗纳尔多", content: "质量不错，很好，好评" }],

	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		var that = this
		utils.GET({
			url: 'Category/details',
			params: {
				id: options.id

			},
			success: function (res) {
				console.log(res.data)
				that.setData({
					phonenum: res.data.t,
					imgs: res.data.img,
					pro: res.data.g,
					phonenum:res.data.t

				})
			},
		})
	},
	swiper2:function(e){
		this.setData({
			coindex:e.detail.current
		})
	},
	swiper1: function (e) {
		this.setData({
			imgindex: e.detail.current
		})
	},
	phonetap:function(){
		var phonenum=this.data.phonenum
		wx.makePhoneCall({
			phoneNumber: phonenum,
		})
	},
	gobuy:function(){
		wx.navigateTo({
			url: 'submit',
		})
	},
	shoucang:function(){
		var that=this
		var id=that.data.pro.id
		utils.GET({
			url: 'Category/collect',
			params: {
				gid:id,
				uid: wx.getStorageSync('uid')

			},
			success: function (res) {
				if(res.data.status==1){
					wx.showToast({
						title: '收藏成功',
					})
				}
			},
		})
	}, 
	gocart:function(){
wx.switchTab({
	url: '/pages/cart/index',
})
	},
	addcart:function(){
		var that=this
		var id = that.data.pro.id
		utils.GET({
			url: 'Category/addcart',
			params: {
				gid: id,
				uid: wx.getStorageSync('uid')

			},
			success: function (res) {
				if (res.data.status == 1) {
   wx.showToast({
	   title: '加入购物车成功',
   })
				}
			},
		})
	}
})